package com.lottery.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map.Entry;

import com.lottery.service.pc28.customService.CostomerServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lottery.entity.CommunionMsg;

public class DeleteServerMsgThread extends Thread {

	private boolean isLoop = true;

	private static final Logger logger = LoggerFactory.getLogger(DeleteServerMsgThread.class);

	@Override
	public void run() {

		long endTime;
		logger.debug("************check map thread start************");
		CustomerContext customerContext = CustomerContext.getInstance();
		while (isLoop) {
			try {
				logger.debug("************isLooping************");
				endTime = System.currentTimeMillis() / 1000;
				for (Entry<Integer, CostomerServer> serverMsg : customerContext.getServersMap().entrySet()) {
					CostomerServer costomerServer = serverMsg.getValue();
					for (Entry<Integer, ArrayList<CommunionMsg>> clientMsg : costomerServer.getMessageList()
							.entrySet()) {
						Iterator<CommunionMsg> iter = clientMsg.getValue().iterator();
						while (iter.hasNext()) {
							CommunionMsg s = iter.next();
							if (endTime - s.getiSendTime() > 30 * 60) {
								iter.remove();
							}
						}
					}
				}
				Thread.sleep(5 * 60 * 1000);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
